package net.zoneland.knowledge.service.impl;

import com.google.common.base.Preconditions;
import net.zoneland.knowledge.controller.bean.SanHuiYiKeVo;
import net.zoneland.knowledge.exceptions.DjExceptionCode;
import org.apache.commons.lang.StringUtils;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

/**
 * 智巡的abstract
 * @author zx
 */
public abstract class AbstractZhiXumServiceImpl {

    /**
     * 核对参数.
     * @param sanHuiYiKeVo
     */
    protected  abstract void checkParam(SanHuiYiKeVo sanHuiYiKeVo);

    /**
     * 处理参数.
     * @param sanHuiYiKeVo 对象
     */
    void handlerParam(SanHuiYiKeVo sanHuiYiKeVo) {
        Preconditions.checkArgument(StringUtils.isNotBlank(sanHuiYiKeVo.getMeetingName()), DjExceptionCode.SanHuiYiKeExceptionCode.MEETING_NAME_NULL);
        Optional.ofNullable(sanHuiYiKeVo.getMeetingStartTime())
                .ifPresent(s -> sanHuiYiKeVo.setMeetingEndTime(Optional.ofNullable(sanHuiYiKeVo.getMeetingEndTime()).
                        orElseGet(LocalDate::now)));
    }

    /**
     * 会议名称转换成list,用空格隔开.
     * @param sanHuiYiKeVo 会议名称
     */
    protected void meetingNameToList(final SanHuiYiKeVo sanHuiYiKeVo) {
        sanHuiYiKeVo.setMeetingNames(Optional.ofNullable(sanHuiYiKeVo.getMeetingName())
                .map(String::trim)
                .map(name -> name.split(" "))
                .map(Arrays::asList)
                .orElseGet(Collections::emptyList));
    }
}
